package com.ayi.servlet.backstage; /**
 * @author Ayingzz
 * @create 2021/12/2 16:09
 */

import com.ayi.bean.Book;
import com.ayi.dao.bookdao.AddBook;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "addBookIntoBooksServlet", value = "/addBookIntoBooksServlet")
public class addBookIntoBooksServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        String bookname = request.getParameter("bookname");
        String bookauthor = request.getParameter("bookauthor");
        String booktype = request.getParameter("booktype");
        String bookprice = request.getParameter("bookprice");
        String bookinventory = request.getParameter("bookinventory");
        String bookdetails = request.getSession().getAttribute("bookdetails").toString();
        String bookimg = request.getSession().getAttribute("img").toString();
        Book book = new Book();
        book.setName(bookname);
        book.setAuthor(bookauthor);
        book.setType(booktype);
        book.setPrice(Double.parseDouble(bookprice));
        book.setInventory(Integer.parseInt(bookinventory));
        book.setDetails(bookdetails);
        book.setImgPath(bookimg);
        request.getSession().setAttribute("allow", null);
        if (new AddBook().addBook(book)) {
            request.getRequestDispatcher("BackStageServlet").forward(request, response);
        } else {

        }
    }
}
